<?php include("src/addNomina_cs.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href='css/coolMessage.css' type='text/css' rel='stylesheet' media='screen' />

<title>Adicionar Recibo Empresa :: ASSC</title>
<script language="javaScript" type="text/javascript" src="js/jquery.js"></script>
<script language="javaScript" type="text/javascript" src="js/jquery.simplemodal.js"></script>
<script language="javaScript" type="text/javascript" src="js/coolMessage.js"></script>

<link rel="stylesheet" type="text/css" media="all" href="includes/calendario/calendar-system.css" title="system" />
<script type="text/javascript" src="includes/calendario/calendar.js"></script>
<script type="text/javascript" src="includes/calendario/lang/calendar-es.js"></script>
<script type="text/javascript" src="includes/calendario/calendar-setup.js"></script>
	<script type="text/javascript" src="js/ajax.js"></script>
	<script type="text/javascript" src="js/ajax-dynamic-list-company.js"></script>
<script language="javascript" type="text/javascript">
	
	var displayRow = '';
	if (navigator.appName == "Netscape")
		displayRow = 'table-row';
	else if (navigator.appName.indexOf("Explorer") != -1) 
		displayRow = 'block';
	
	

	
	/**
	*	Función encargada de extraer la informacion de una etiqueta.
	*	@parameter: data->informacion que contiene una o varias etiquetas con información.
	*				lbl->etiqueta específica que contiene la infomación.
	*	@autor: jsl.
	*	@date: 12 AGO 2011	
	*/
	function getDataXML(data,label){				
		var label_open = '<'+label+'>';
		var label_close = '</'+label+'>';
		var inicio = data.indexOf(label_open);
		inicio += label_open.length;//la informacion esta desps de abrir la etiqueta
		var fin = data.indexOf(label_close);
		var result = data.substring(inicio,fin);//la info esta entre la etiqueta.
		return result;
	}
	
	function validate(action){
		
        document.getElementById("action").value = action;//1: save, 2: save and continue.
		
		var msg = ''; 
        var count  = document.getElementById("count").value;
        var desde  = document.getElementById("desde").value;
        var hasta  = document.getElementById("hasta").value;
        var nombre = Array();
        var valor1 = Array();
        
        if (desde=='')
            msg += 'la fecha de inicio es obligatoria \n';
        if (hasta=='')
            msg += 'la fecha final es obligatoria \n';
        
		for (i=0; i<count;i++){
		   nombre[i] = document.getElementById("nombre"+i).value;
		   valor1[i] = document.getElementById("valor1_"+i).value;
           if (valor1[i]=='')
            msg += 'el numero de dias para '+nombre[i]+' es obligatorio \n';
		}
        
        
			
		
	
//		if(cli_email == '') 
//			msg='- Please enter the email. <br />';
//		else{
//			if ( ! isMail (cli_email) )
//				msg += '- Wrong email.<br />';
//		}
		
		

		if(msg==''){
			document.getElementById('form').submit();
			return true;
		}
		else{
			coolMessage("alert", msg);
			return false;
		}		
	}
	

	function onlyNumbers(e)
	{
	   var key;
	   if(window.event)
		  key = window.event.keyCode;   //IE
	   else
		  key = e.which;                //firefox
	   if (!( (key >= 48 && key <= 57) || key ==8 || key ==9 || key ==0 || key ==46 ))
		  return false;
	   else
		  return true;
	}	
	

$(document).ready(loadSalarioCompany());

function loadSalarioCompany()
{	
    var msg = ''; 
        var count  = document.getElementById("count").value;
        var desde  = document.getElementById("desde").value;
        var hasta  = document.getElementById("hasta").value;
        var code = document.getElementById('country_hidden').value;
        
        if (desde=='')
            msg += 'la fecha de inicio es obligatoria. \n';
        if (hasta=='')
            msg += 'la fecha final es obligatoria. \n';
        if (code == '')
            msg += 'Debe seleccionar una Compania.';
            if (msg == ''){
	
	$.ajax({
		type: "POST",
		url: "loadPayRollCompany.php",
		data: 'code='+code+'&ini='+desde+'&fin='+hasta,
		success: function(msg)
		{	
            var resultadoCompanyCode = getDataXML(msg,"company_code");		
			
			var resultadoNombreCompany = getDataXML(msg,"company_name");		
			
			var resultadoNombreCompanyNit = getDataXML(msg,"company_nit");		
			document.getElementById('div_company_nit').innerHTML = resultadoNombreCompanyNit;
			
			var resultadoCompanyAddress = getDataXML(msg,"company_address");		
			document.getElementById('div_company_address').innerHTML =  resultadoCompanyAddress;
            
            var resultadoCompanyEmpleados = getDataXML(msg,"empleados");		
			document.getElementById('div_empleados').innerHTML =  resultadoCompanyEmpleados;
            
            var resultadoCountRow= getDataXML(msg,"contRow");
            document.getElementById('count').value =  resultadoCountRow;
            
		}
		
		});
        } else{
            coolMessage("alert", msg);
			return false;
        }
        
	
}

function calcularTotal(numNomina)
{
	var dias   = 0;
	var base   = 0;
	var valor1 = 0;
    var der    = 0;
    var aux    = 0;
    var con    = 0;
    var total  = 0;
    var desc   = 0;
    var ah      = 0;
    var ap      = 0;
    var salud   = 0;
    var pension = 0;
    var neto    = 0;
    var Tdias   = 0;
	var Tbase   = 0;
	var Tvalor1 = 0;
    var Tder    = 0;
    var Taux    = 0;
    var Tcon    = 0;
    var Ttotal  = 0;
    var Tdesc   = 0;
    var Tah      = 0;
    var Tap      = 0;
    var Tsalud   = 0;
    var Tpension = 0;
    var Tneto    = 0;
    var Eeps     = 0;
    var Earl     = 0;
    var Epension = 0;
    var Eparafiscales     = 0;
    var Etotal  = 0;
    var TEeps     = 0;
    var TEarl     = 0;
    var TEpension = 0;
    var TEparafiscales     = 0;
    var TEtotal  = 0;
    
    
    var contador = document.getElementById("count").value;
    
	if(document.getElementById('basico'+numNomina).value!='')
	base = parseInt(document.getElementById('basico'+numNomina).value);
    
    if(document.getElementById('dias'+numNomina).value!='')
	dias = parseInt(document.getElementById('dias'+numNomina).value);	
	
	if(document.getElementById('der'+numNomina).value!='')
	der = parseInt(document.getElementById('der'+numNomina).value);	
    
    if(document.getElementById('con'+numNomina).value!='')
	con = parseInt(document.getElementById('con'+numNomina).value);
    
    if(document.getElementById('descu'+numNomina).value!='')
	desc = parseInt(document.getElementById('descu'+numNomina).value);
    
    if(document.getElementById('AH'+numNomina).value!='')
	ah = parseInt(document.getElementById('AH'+numNomina).value);
    
    if(document.getElementById('AP'+numNomina).value!='')
	ap = parseInt(document.getElementById('AP'+numNomina).value);
    
	valor1 = base*dias/30;
    document.getElementById('valor1_'+numNomina).value = valor1;
    
    aux = 70500*dias/30;
    document.getElementById('aux'+numNomina).value = aux;
    
	salud = pension = valor1*.04;
    document.getElementById('salud'+numNomina).value = salud;

    document.getElementById('pension'+numNomina).value = pension;
    
	total = valor1+der+aux+con;
	document.getElementById('total'+numNomina).value = total; 
    
    neto = total-salud-ap-ah-desc-pension;
    document.getElementById('neto'+numNomina).value = neto;
    
    Eeps = valor1*0.085;
    document.getElementById('Eeps'+numNomina).value = parseInt(Eeps);
    
    Earl = valor1*0.0435;
    document.getElementById('Earl'+numNomina).value = parseInt(Earl);
    
    Epension = valor1*0.12;
    document.getElementById('Epension'+numNomina).value = parseInt(Epension);
    
    Eparafiscales = valor1*0.09;
    document.getElementById('Eparafiscales'+numNomina).value = parseInt(Eparafiscales);
    
    Etotal = Eeps+Earl+Epension+Eparafiscales;
    document.getElementById('Etotal'+numNomina).value = parseInt(Etotal);
    
    for (i=0;i<contador;i++){
        if (parseInt(document.getElementById('basico'+i).value)>=0)
        Tbase    += parseInt(document.getElementById('basico'+i).value);
        
        if(parseInt(document.getElementById('dias'+i).value) >= 0)
            Tdias    += parseInt(document.getElementById('dias'+i).value);
            
       if(parseInt(document.getElementById('valor1_'+i).value) >= 0)
    	   Tvalor1  += parseInt(document.getElementById('valor1_'+i).value);
           
        if(parseInt(document.getElementById('der'+i).value) >= 0)
            Tder     += parseInt(document.getElementById('der'+i).value);
            
        if(parseInt(document.getElementById('aux'+i).value) >= 0)  
            Taux     += parseInt(document.getElementById('aux'+i).value);
            
         if(parseInt(document.getElementById('con'+i).value) >= 0)
            Tcon     += parseInt(document.getElementById('con'+i).value);
            
         if(parseInt(document.getElementById('total'+i).value) >= 0)
            Ttotal   += parseInt(document.getElementById('total'+i).value);
            
         if(parseInt(document.getElementById('descu'+i).value) >= 0)
            Tdesc    += parseInt(document.getElementById('descu'+i).value);
            
         if(parseInt(document.getElementById('AH'+i).value) >= 0)
            Tah      += parseInt(document.getElementById('AH'+i).value);
                        
         if(parseInt(document.getElementById('AP'+i).value) >= 0)
            Tap      += parseInt(document.getElementById('AP'+i).value);
                        
         if(parseInt(document.getElementById('salud'+i).value) >= 0)
            Tsalud   += parseInt(document.getElementById('salud'+i).value);
                        
         if(parseInt(document.getElementById('pension'+i).value) >= 0)
            Tpension += parseInt(document.getElementById('pension'+i).value);
         
         if(parseInt(document.getElementById('neto'+i).value) >= 0)
            Tneto += parseInt(document.getElementById('neto'+i).value);
         
         if(parseInt(document.getElementById('Eeps'+i).value) >= 0)
            TEeps += parseInt(document.getElementById('Eeps'+i).value);
            
         if(parseInt(document.getElementById('Earl'+i).value) >= 0)
            TEarl += parseInt(document.getElementById('Earl'+i).value);
            
         if(parseInt(document.getElementById('Epension'+i).value) >= 0)
            TEpension += parseInt(document.getElementById('Epension'+i).value);
            
        if(parseInt(document.getElementById('Eparafiscales'+i).value) >= 0)
            TEparafiscales += parseInt(document.getElementById('Eparafiscales'+i).value);
            
        if(parseInt(document.getElementById('Etotal'+i).value) >= 0)
            TEtotal += parseInt(document.getElementById('Etotal'+i).value);
    }
     document.getElementById('Tbasico').value  = Tbase;
     document.getElementById('Tdias').value    = Tdias;
     document.getElementById('Tvalor1_').value = Tvalor1;
     document.getElementById('Tder').value     = Tder;
     document.getElementById('Taux').value     = Taux;
     document.getElementById('Tcon').value     = Tcon;
     document.getElementById('Ttotal').value   = Ttotal;
     document.getElementById('Tdescu').value   = Tdesc;
     document.getElementById('TAH').value      = Tah;
     document.getElementById('TAP').value      = Tap;
     document.getElementById('Tsalud').value   = Tsalud;
     document.getElementById('Tpension').value = Tpension;
     document.getElementById('Tneto').value    = Tneto;
     document.getElementById('TEeps').value    = TEeps;
     document.getElementById('TEarl').value    = TEarl;
     document.getElementById('TEpension').value         = TEpension;
     document.getElementById('TEparafiscales').value    = TEparafiscales;
     document.getElementById('TEtotal').value           = TEtotal;
}



</script>
<style type="text/css">
	
	/* START CSS NEEDED ONLY IN DEMO */

	#mainContainer{
		width:660px;
		margin:0 auto;
		text-align:left;
		height:100%;
		background-color:#FFF;
		border-left:3px double #000;
		border-right:3px double #000;
	}
	#formContent{
		padding:5px;
	}
	/* END CSS ONLY NEEDED IN DEMO */
	
	
	/* Big box with list of options */
	#ajax_listOfOptions{
		position:absolute;	/* Never change this one */
		width:175px;	/* Width of box */
		height:250px;	/* Height of box */
		overflow:auto;	/* Scrolling features */
		border:1px solid #317082;	/* Dark green border */
		background-color:#FFF;	/* White background color */
		text-align:left;
		font-size:12px;
		z-index:100;
	}
	#ajax_listOfOptions div{	/* General rule for both .optionDiv and .optionDivSelected */
		margin:1px;		
		padding:1px;
		cursor:pointer;
		font-size:12px;
	}
	#ajax_listOfOptions .optionDiv{	/* Div for each item in list */
		
	}
	#ajax_listOfOptions .optionDivSelected{ /* Selected item in the list */
		background-color:#317082;
		color:#FFF;
	}
	#ajax_listOfOptions_iframe{
		background-color:#F00;
		position:absolute;
		z-index:5;
	}
	
	form{
		display:inline;
	}
	
	</style>
</head>
<body>
<?php $item_select = 15;include("menu.php");?><br />
    <form name="form" id="form" method="post" action="" enctype="multipart/form-data">
    
	<input type="hidden" name="action" id="action" value="1" />
    <input type="hidden" name="addNomina" id="addNomina" value="1" />
    <input type="hidden" name="count" id="count" />
	<input type="hidden" name="country_hidden"  id="country_hidden" />
    
    <div class="content_grv">
		<table width="90%" align="center" class="shadow">
            <tr>
                <td class="title">Nomina </td>
            </tr>
            <tr>
                <td>
                    <table class="tbl_form" align="center">
                        <tr>
                            <td class="title">SERVICIOS Y SOLUCIONES</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td><div><span class="lbl_gray">NIT : 900334306-7</span></div>
                            <div><span class="lbl_gray">CR 15 N.18-22 L3 ED.SOLIDARIDAD</span></div>
                            <div><span class="lbl_gray">TEL : 7440622</span></div></td>
                        </tr>
                    </table>
                    <table class="tbl_form" align="center" >
                         <tr>
                            <td colspan="5">Periodo de Nomina Comprendido:</td>
                         </tr>
                         <tr>
                            <td>&nbsp;</td>
                            <td width="10%" align="right"><span class="lbl_gray">Desde:</span></td>
                            <td width="10%"><input name="desde" type="text" style="width:100px" readonly="readonly" id="desde" maxlength="45" class="text_grv"/></td>
							<td align="left"><input name="imagea" type="image" id="calendar1" src="images/mostrar_calendario.png" align="absmiddle" width="18" height="16"/></td>
                            <td>&nbsp;</td>
                                    
                                    <script type="text/javascript">
        						Calendar.setup({
        						inputField : "desde",							
        						ifFormat : "%d/%m/%Y",
        						showsTime : false,
        						button : "calendar1", 
        						step : 1
        						});
        				</script>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td width="10%" align="right"><span class="lbl_gray">Hasta:</span></td>
                            <td width="10%"><input name="hasta" type="text" style="width:100px" readonly="readonly" id="hasta" maxlength="45" class="text_grv"/></td>
							<td align="left"><input name="imagea" type="image" id="calendar2" src="images/mostrar_calendario.png" align="absmiddle" width="18" height="16"/></td>
                            <td>&nbsp;</td>
                                    
                                    <script type="text/javascript">
        						Calendar.setup({
        						inputField : "hasta",							
        						ifFormat : "%d/%m/%Y",
        						showsTime : false,
        						button : "calendar2", 
        						step : 1
        						});
        				</script>
                        </tr>
                    </table> 
                    <table class="tbl_form" align="center" >             
                        <tr>
                            <td align="left" width="10%"><span class="lbl_gray">Compania :</span></td>
                            
                            <td><input type="text" id="country" name="country" value="" onkeyup="ajax_showOptions(this,'getCountriesByLetters',event)"  size="30" autocomplete="off" /></td>
        					<td align="left"><input type="button" value="Procesar" onclick="javascript: loadSalarioCompany()" /> </td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td align="left"><span class="lbl_gray">Direccion :</span></td>
                            <td><div id="div_company_address"></div></td>
                            <td>&nbsp;</td>
                            <td><div>
                        	<input type="hidden" name="country_hidden"  id="country_hidden" maxlength="20"    />
                    </div></td>
                            <td>&nbsp;</td>
                            
                        </tr>
                        <tr>
                            <td align="left"><span class="lbl_gray">Nit :</span></td>
                            <td><div id="div_company_nit"></div></td>
                            <td>&nbsp;</td>
                            <td></td>
                            <td>&nbsp;</td>
                        </tr>
                    </table>
                                          
                        <div id="div_empleados"></div>
                        
                        <table class="tbl_form" align="center" >
                        <tr style="background-color:#808080">
                            <td align="left" style="color:#FFFBF0" colspan="3" width="68%">TOTAL:</td>
							<td align="right" width="5%">$</td>
                            <td><input type="text" name="input_eps" id="input_eps" readonly="readonly" size="21"/></td>
                           
                        </tr>
                        
                        <tr>
                            <td colspan="6" align="center">
                                <input type="button" class="button_grv" value="Save" onclick="javascript: return validate(1);" />
                                <input type="button" class="button_grv" value="Save and continue" onclick="javascript: return validate(2);" />
                                <input type="reset" value="Reset" class="button_grv_cancel"/>
                                <input type="button" class="button_grv_cancel" value="Cancel" onClick="javascript:window.location.href='listEmpresarialDependiente.php';" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
 	</div>
</form>    
</body>
</html>

<script language="javascript" type="application/javascript">


/*
    Si se presiona la tecla enter debe cargar una nueva fila
    para eso es necesario validar que el campo no sea vacio.
    */
    function validarEnter(e)
    {
 		var key;
		if(window.event){
			key = window.event.keyCode;   //IE
		}else
			key = e.which;                //firefox
		if (key == 13){
			//most();
		}    
    }


</script>
<?php include('divscoolmessage.php');?>